/*
 * Copyright 2009-2010 Original Author(s)
 * 
 * This file is part of Kommando
 * 
 * Kommando is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Kommando is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Kommando.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kommando.text.actions;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;

import javax.swing.Icon;
import javax.swing.ImageIcon;

import org.kommando.core.action.ActionExecutionException;
import org.kommando.core.catalog.CatalogObject;
import org.kommando.text.actions.support.TextAction;

/**
 * Copy the text to the clipboard.
 * 
 * @author Peter De Bruycker
 */
public class CopyAction extends TextAction {

    private static final String ID = "text:copy";
    private Icon icon;

    @Override
    public String getDescription() {
        return "Copy the text to the clipboard";
    }

    @Override
    public Icon getIcon() {
        if (icon == null) {
            icon = new ImageIcon(getClass().getResource("/icons/edit-copy_256x256x32.png"));
        }

        return icon;
    }

    @Override
    public String getId() {
        return ID;
    }

    @Override
    public String getName() {
        return "Copy";
    }

    @Override
    protected CatalogObject execute(String text, CatalogObject indirect) throws ActionExecutionException {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(new StringSelection(text), null);

        return null;
    }

}
